import time

from appium.webdriver.common.appiumby import By

from tools import app_driver, driver_quit


def app_index_page(driver):  #首页滑动
    time.sleep(3)
    for i in range(3):
        driver.swipe(start_x=1000, start_y=1000, end_x=500,end_y=1000)
    time.sleep(3)

def app_search_page(driver,keyword):  #搜索
    time.sleep(2)
    driver.find_element(by=By.ID,value='com.tpshop.malls:id/home_ll').click()
    time.sleep(2)
    driver.find_element(by=By.ID,value='com.tpshop.malls:id/default_search_et').click()
    time.sleep(2)
    driver.find_element(by=By.ID,value='com.tpshop.malls:id/search_et').send_keys(keyword)
    driver.find_element(by=By.ID,value='com.tpshop.malls:id/search_btn').click()


def app_buy_now(driver):
    driver.find_element(by=By.ID,value='com.tpshop.malls:id/product_pic_img').click()
    driver.find_element(by=By.ID,value='com.tpshop.malls:id/promptly_buy_tv').click()
    driver.find_element(by=By.ID,value='com.tpshop.malls:id/confirm_tv').click()



if __name__ == '__main__':
    driver = app_driver()
    app_index_page(driver)
    app_search_page(driver)
    time.sleep(2)
    driver_quit(driver)